home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
028a
/
arcutils.zip
/
CONVERT.C
next >
Wrap
C/C++ Source or Header
|
1989-04-20
|
5KB
|
178 lines
#include <dos.h>
#include <stdio.h>
#include <dir.h>
#include <stdlib.h>
main(argc,argv)
int argc;
char *argv[];
{
char string[80],string2[80],string3[15],ext[20][5],method[20][50],
ext2[20][5],method2[20][50];
FILE *file;
int i,j,type,done,number=0,number2=0;
struct ffblk ffblk;
typedef struct file_stack FILES;
struct file_stack { /* holds a directory listing */
char string[13];
FILES *next;
};
FILES *head,*tail,*temp_hold;
printf("Archive Format Converter.\n");
printf("Ver 1.05\nDave Harris 1:302/5\n\n");
if (argc==1)
strcpy(string3,"*.*");
else
strcpy(string3,argv[1]);
if (!strstr(string3,"."))
strcat(string3,".*");
/*************************************************************************/
/* open the configuration file, look through path if necessary */
file=fopen("convert.cfg","r");
if (file==NULL) { /* ok, its not in the current */
int pathpos=0,dirpos; /* directory so lets trudge through */
char path[200],directory[80]; /* the PATH */
strcpy(path,getenv("PATH"));
while (1) {
dirpos=0;
while (path[pathpos]!=';' && path[pathpos]!=NULL) {
directory[dirpos++]=path[pathpos++];
}
if (path[pathpos]==NULL) { /* we have looked through the whole
PATH without success */
printf("Can't find CONVERT.CFG\n");
exit(1);
}
pathpos++; /* get us over the ; */
if (directory[dirpos-1]!='\\')
directory[dirpos++]='\\';
directory[dirpos]=NULL;
strcat(directory,"convert.cfg");
file=fopen(directory,"r");
if (file!=NULL)
break;
else
fclose(file);
}
}
/**********************************************************************/
/* parse the configuration file for the control info */
while (fscanf(file,"%s",string)!=EOF) {
if (stricmp(string,"U")==0) {
fscanf(file,"%s",ext[number]);
type=0;
while (1) {
i=getc(file);
if (i=='\n' || i==EOF) {
method[number][type]=NULL;
number++;
break;
}
else
method[number][type++]=i;
}
strupr(ext[number-1]);
}
else {
fscanf(file,"%s",ext2[number2]);
type=0;
while (1) {
i=getc(file);
if (i=='\n' || i==EOF) {
method2[number2][type]=NULL;
number2++;
break;
}
else
method2[number2][type++]=i;
}
strupr(ext2[number2-1]);
}
}
/********************************************************************/
/* get all the file names and put them on the queue */
done=findfirst(string3,&ffblk,0);
if (done)
exit(0);
system("MD conv89"); /* temporary storage */
head=(FILES*)malloc(sizeof(FILES));
strcpy(head->string,ffblk.ff_name);
head->next=NULL;
tail=head;
while (!done) {
done=findnext(&ffblk);
if (done)
break;
temp_hold=(FILES*)malloc(sizeof(FILES));
strcpy(temp_hold->string,ffblk.ff_name);
tail->next=temp_hold;
tail=temp_hold;
tail->next=NULL;
}
/********************************************************************/
while (head!=NULL) {
strcpy(string,head->string);
for (i=0;i<number;i++) {
if (strstr(string,ext[i])!=NULL) {
printf("Converting %s\n",string);
sprintf(string2,"RED %s conv89",string);
system(string2);
system("CD conv89");
sprintf(string2,method[i],string);
system(string2);
remove(string);
for (i=0;i<number2;i++) {
j=0;
while (1) {
if (string[j]=='.') {
string[j]=NULL;
strcat(string,ext2[i]);
break;
}
j++;
}
sprintf(string2,method2[i],string);
system(string2);
sprintf(string2,"RED %s ..",string);
system(string2);
}
done=findfirst("*.*",&ffblk,0); /* del *.* */
if (done)
break;
while (!done) {
remove(ffblk.ff_name);
done=findnext(&ffblk);
}
system("CD ..");
break;
}
}
temp_hold=head;
head=head->next;
free(temp_hold); /* clean up behind */
}
system("RD conv89");
}